<?php
/*
	提现
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
global $_RQ;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
cfc('core')->checklogin();
$credit_types=credit_types(true);
if($_RQ['op']=='get'){
    $return['jifenset']=$this->plugin_setting('jifenbasic');
	$up_type=$tixianset['up_type']?:3;
	if($_SESSION['onemerchid']){
		$member=model('jy_merch/member')->getdetail($_SESSION['onemerchid'],$_SESSION['uid']);
	}else{
		$member=pdo_get('core_members',array('id'=>$_SESSION['uid']));
	}
	$tinum=intval($return['allmoney']/$tixianset['man_fee']);
	$return['man_fee']=$tixianset['man_fee'];
	$return['member']=$member;
	$return['params']['type']=$_RQ['type']?:3;
	$return['allmoney']=$member['credit'.$return['params']['type']];
	$return['typetitle']=$credit_types[$return['params']['type']];
	if($return['params']['type']==3){
		$tips='购买商品，参与分享都可以获得《'.$return['typetitle'].'》哦！';
	}elseif($return['params']['type']==4){
		$tips='可以充值获得《'.$return['typetitle'].'》哦！';
	}if($return['params']['type']==6){
		$tips='签到，直推人参与拼团，购买指定商品，都可以获得《'.$return['typetitle'].'》哦！';
	}
	$return['tips']=$tips;
	$return['is_open']=$tixianset['is_open'];
	$return['open_upbaofee']=$tixianset['open_upbaofee'];
	$return['post']=array();
	set_html('title','我的'.$return['typetitle']);
	exi($return);
}
if($_RQ['op']=='fenlist'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']);
	if($_RQ['type']){
		$params['type']=intval($_RQ['type']);
	}
    $orderby='createtime desc';
	$total='';
	$list=pdo_getslice('core_credit_log',$params,array($pindex,$psize),$total,array('id','type','is_add','fee','remark','createtime'),'','id desc');
	if($list){
		foreach($list as &$item){
			$item['createtime']=date('Y/m/d H:i:s',$item['createtime']);
			$item['is_addtitle']=$item['is_add']?'获得':'消费';
			$item['typetitle']=$credit_types[$item['type']];
		}
	}
	$return['list']=$list;
	exi($return);
}
if($_RQ['op']=='zhuan3'){
    $post=get_postdata();
    $member=pdo_get('core_members',array('id'=>$_SESSION['uid']));
    if(!$post['fee']){
        exi('请输入兑换额度！','erroe');
    }
    $jifenset=$this->plugin_setting('jifenbasic');
    if(!$jifenset['bi3to1']){
        exi('未设置该兑换比率！','erroe');
    }
    $credit1=$post['fee']/$jifenset['bi3to1'];
    if($member['credit3']<$post['fee']){
        exi('兑换额度不能大于，当前剩余额度！','erroe');
    }
    model('core/member')->member_credit($_SESSION['uid'],'credit3',$post['fee'],false,'jy_guashop','兑换积分');
    model('core/member')->member_credit($_SESSION['uid'],'credit1',$credit1,true,'jy_guashop',$credit_types[3].'的兑换');
    exi('兑换成功！');
}
if($_RQ['op']=='zhuan4'){
    $post=get_postdata();
    $member=pdo_get('core_members',array('id'=>$_SESSION['uid']));
    if(!$post['fee']){
        exi('请输入兑换额度！','erroe');
    }
    $jifenset=$this->plugin_setting('jifenbasic');
    if(!$jifenset['bi6to4'] && !$jifenset['bi6to4']){
        exi('未设置该兑换比率！','erroe');
    }
    $credit6=$jifenset['bi6to4']*$post['fee'];
    $credit1=$jifenset['bi1to4']*$post['fee'];
    if($member['credit6']<$credit6){
        exi('兑换额度不能大于，当前剩余'.$credit_types[6].'额度！','erroe');
    }
    if($member['credit1']<$credit1){
        exi('兑换额度不能大于，当前剩余积分额度！','erroe');
    }
    model('core/member')->member_credit($_SESSION['uid'],'credit6',$credit6,false,'jy_guashop','兑换'.$credit_types[4]);
    model('core/member')->member_credit($_SESSION['uid'],'credit1',$credit1,false,'jy_guashop','兑换'.$credit_types[4]);
    model('core/member')->member_credit($_SESSION['uid'],'credit4',$post['fee'],true,'jy_guashop','兑换获得');
    exi('兑换成功！');
}